// Copyright (C) 2010 Razvan Constantin <razvan.constantin@rconst.net>
//
// This file is part of FileBow.
//
// FileBow is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// FileBow is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FileBow.  If not, see <http://www.gnu.org/licenses/>.

#include "logic/file-scorer.h"

#include <gtest/gtest.h>
#include <Poco/Path.h>

#include "logic/path-tree.h"

using namespace std;
using Poco::Path;

namespace filebow {

TEST(DefaultScorerTest, TestScore) {
  PathTree pt;
  DefaultScorer scorer;
  scorer.SetScore(pt.Insert("testdata/foo.txt"), 10);
  scorer.SetScore(pt.Insert("testdata/bar.txt"), 3);
  scorer.SetScore(pt.Find("testdata"), 2);
  EXPECT_EQ(2, scorer.ScoreDir(pt.Find("testdata")));
  EXPECT_EQ(3, scorer.ScoreFile(pt.Find("testdata/bar.txt")));
  EXPECT_EQ(10, scorer.ScoreFile(pt.Find("testdata/foo.txt")));
}

TEST(SimilarScorerTest, TestScore) {
  PathTree pt;
  SimilarScorer scorer(Path("/src/myfile_test.cpp").getBaseName());
  EXPECT_EQ(106, scorer.ScoreFile(pt.Insert("/testdata/myfile.h")));
  EXPECT_EQ(106, scorer.ScoreFile(pt.Insert("/testdata/myfile.cpp")));
  EXPECT_EQ(106, scorer.ScoreFile(pt.Insert("/testdata/myfile-impl.cpp")));
  EXPECT_EQ(111, scorer.ScoreFile(pt.Insert("/testdata/myfile_test.h")));
}

TEST(ClosestScorerTest, TestScore) {
  PathTree pt;
  ClosestScorer scorer(pt.Insert("/src/base/file.h")->parent());
  EXPECT_EQ(100, scorer.ScoreDir(pt.Insert("/src/base/myotherfile.h")->parent()));
  EXPECT_EQ(10, scorer.ScoreDir(pt.Insert("/test/base/mytestfile.cpp")->parent()));
  EXPECT_EQ(20, scorer.ScoreDir(pt.Insert("/impl/src/base/file.cpp")->parent()));
}

} // namespace filebow
